package com.yk.anima.controller;

import com.yk.anima.api.ShoppingCartApi;
import com.yk.anima.pojo.ShoppingCart;
import com.yk.anima.response.QueryResponseResult;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.ShoppingCarServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaokai
 * @create 2021-05-13 22:41:04
 * @desc...对购物车进行管理
 */
@RestController
@RequestMapping("/cart")
public class ShoppingCarController implements ShoppingCartApi {

    @Autowired
    ShoppingCarServlet shoppingCarServlet;

    /**
     * @param aId      用户ID
     * @param animalId 宠物归属类ID
     * @param id       宠物ID
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 把宠物添加到购物车
     * @Date 9:57 2021/5/15
     */
    @Override
    @PostMapping("/save/{aId}/{animalId}/{id}")
    public ResponseResult save(@PathVariable("aId") int aId,
                               @PathVariable("animalId") int animalId, @PathVariable("id") int id) {
        return shoppingCarServlet.save(aId, animalId, id);
    }

    /**
     * @param cartAdminId
     * @return com.yk.anima.pojo.ShoppingCart
     * @Author xiaoKai
     * @Description 用户根据ID查询自己的购物车
     * @Date 15:12 2021/5/15
     */
    @Override
    @GetMapping("/findById/{cartAdminId}")
    public List<ShoppingCart> findById(@PathVariable("cartAdminId") int cartAdminId) {
        return shoppingCarServlet.findById(cartAdminId);
    }

    /**
     * @param cartAdminId 用户ID
     * @param sId         当前物品ID
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 用户根据ID删除购物车的物品
     * @Date 15:21 2021/5/15
     */
    @Override
    @DeleteMapping("/deleteById/{cartAdminId}/{sId}")
    public ResponseResult deleteById(@PathVariable("cartAdminId") int cartAdminId, @PathVariable("sId") int sId) {
        return shoppingCarServlet.deleteById(cartAdminId, sId);
    }

    /**
     * @param
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 根据用户ID清除自己的购物车
     * @Date 15:28 2021/5/15
     */
    @Override
    @DeleteMapping("/clear/{cartAdminId}")
    public ResponseResult clear(@PathVariable("cartAdminId") int cartAdminId) {
        return shoppingCarServlet.clear(cartAdminId);
    }

    /**
     * @param cartAdminId
     * @param sId
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 添加购物车中物品的数量
     * @Date 15:38 2021/5/15
     */
    //@ApiParam("宠物归属类Id") int animalId,@ApiParam("当前宠物ID") int id
    @Override
    @PutMapping("/updateById/{cartAdminId}/{sId}/{animalId}/{id}")
    public ResponseResult updateByNumAdd(@PathVariable("cartAdminId") int cartAdminId, @PathVariable("sId") int sId,
                                                 @PathVariable("animalId") int animalId,@PathVariable int id) {
        return shoppingCarServlet.updateByNumAdd(cartAdminId, sId,animalId,id);
    }

    /**
     * @param cartAdminId 用户Id
     * @param sId         宠物ID
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description 减少购物车中的数量
     * @Date 15:46 2021/5/15
     */
    @Override
    @PutMapping("/updateByNumLess/{cartAdminId}/{sId}/{animalId}/{id}")
    public ResponseResult updateByNumLess(@PathVariable("cartAdminId") int cartAdminId, @PathVariable("sId") int sId,
                                          @PathVariable("animalId") int animalId,@PathVariable int id) {
        return shoppingCarServlet.updateByNumLess(cartAdminId, sId,animalId,id);
    }

    @Override
    @GetMapping("/findByPage/{page}/{size}")
    public QueryResponseResult findByPage(@PathVariable("page") int page,
                                          @PathVariable("size") int size, String name) {
        return shoppingCarServlet.findByPage(page,size,name);
    }
}
